import java.util.HashMap;

/**
 * Created by Scott Tiger.
 * User: tomaszsocha
 * Date: 2010-03-29
 * Time: 13:02:21
 */
public class Item {
    private String prefix;
    private String sufix;
    private int waga;
    private Item skladnik1 = null;
    private Item skladnik2 = null;

    private String opis = "";
    private int wagaSuf;
    private int wagaPref;


    public Item(String name,Objeto wagi) {
        this.name = name;
        setWaga(wagi.getWagi().get(name));
    }

    public Item(String name,Item k1,Item k2, HashMap<String,Integer> wagi)
    {
        setName(name);
        skladnik1 = k1;
        skladnik2 = k2;
        opis = k1.getName()+"|"+k2.getName();
        setWaga(wagi.get(name));        
    }



    public Item() {
    }

    public Item(String pref, String type, String suf, Item k1, Item k2, HashMap<String, Integer> wagi) {
        setName(type);
        setPrefix(pref);
        setSufix(suf);
        skladnik1 = k1;
        skladnik2 = k2;
        setWaga(wagi.get(name));
        setWagaPref(wagi.get(prefix));
        setWagaSuf(wagi.get(sufix));
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getSufix() {
        return sufix;
    }

    public void setSufix(String sufix) {
        this.sufix = sufix;
    }



    public Item getSkladnik1() {
        return skladnik1;
    }

    public void setSkladnik1(Item skladnik1) {
        this.skladnik1 = skladnik1;
    }

    public Item getSkladnik2() {
        return skladnik2;
    }

    public void setSkladnik2(Item skladnik2) {
        this.skladnik2 = skladnik2;
    }



    public int getWaga() {
        return waga;
    }

    public void setWaga(int waga) {
        this.waga = waga;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    private String name;

/*    public String getIngredients(){

        if (skladnik1 != null){
            return "("+skladnik1.getIngredients() +"+"+skladnik2.getIngredients()+"=>"+getName()+")";
        }          else  {
            return "("+getName()+")";
        }
    }
    */
   public String getIngredients(){
        String opis = (getPrefix()==null?"":getPrefix()+" ") + (getName()) + (getSufix()==null?"":getSufix()+" ");
        if (skladnik1 != null){
            return "("+skladnik1.getIngredients() +"+"+skladnik2.getIngredients()+"=>("+opis+")";
        }          else  {
            return "("+opis+")";
        }
    }


    public int totalCost() {
        if (skladnik1 == null)
            return 0;

        return skladnik1.totalCost()+skladnik2.totalCost()+1;
    }


     public int getWagaSuf() {
        return wagaSuf;
    }

    public void setWagaSuf(int wagaSuf) {
        this.wagaSuf = wagaSuf;
    }


    public int getWagaPref() {
        return wagaPref;
    }

    public void setWagaPref(int wagaPref) {
        this.wagaPref = wagaPref;
    }

    public String getOpis() {
        return opis;
    }

    public void setOpis(String opis) {
        this.opis = opis;
    }


}
